package cn.hdu.liang.core.service.product;

import cn.hdu.liang.core.bean.product.Feature;
import cn.hdu.liang.core.dao.product.FeatureDao;
import cn.hdu.liang.core.query.product.FeatureQuery;
import cn.itcast.common.page.Pagination;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品属性事务层
 */
@Service
@Transactional
public class FeatureServiceImpl implements FeatureService {

    @Resource
    FeatureDao featureDao;

    public Integer addFeature(Feature feature) {
        return featureDao.addFeature(feature);
    }

    @Transactional(readOnly = true)
    public Feature getFeatureByKey(Integer id) {
        return featureDao.getFeatureByKey(id);
    }

    @Transactional(readOnly = true)
    public List<Feature> getFeaturesByKeys(List<Integer> idList) {
        return featureDao.getFeaturesByKeys(idList);
    }

    public Integer deleteByKey(Integer id) {
        return featureDao.deleteByKey(id);
    }

    public Integer deleteByKeys(List<Integer> idList) {
        return featureDao.deleteByKeys(idList);
    }

    public Integer updateFeatureByKey(Feature feature) {
        return featureDao.updateFeatureByKey(feature);
    }

    @Transactional(readOnly = true)
    public Pagination getFeatureListWithPage(FeatureQuery featureQuery) {
        Pagination p = new Pagination(featureQuery.getPageNo(), featureQuery.getPageSize(), featureDao.getFeatureListCount(featureQuery));
        p.setList(featureDao.getFeatureListWithPage(featureQuery));
        return p;
    }

    @Transactional(readOnly = true)
    public List<Feature> getFeatureList(FeatureQuery featureQuery) {
        return featureDao.getFeatureList(featureQuery);
    }
}
